import Common from '@/api/common.js'
import {organizeArray} from '@/utils/index.js'
const global = {
	namespaced: true,
	state: {
		heightData: {},
		albumData: [],
		cityObject: {},
		shop_car: {
			cartList: [],
			selectCartList: []
		},
		settleList: [],
		addressInfo: {},
		deliveryScope: '',
		userInfo: {},
		allCityList: [],
		allCityComplete: []
	},

	mutations: {
		SET_USERINFO: (state, userInfo) => {
			state.userInfo = userInfo
		},
		SET_DELIVERY: (state, deliveryScope) => {
			state.deliveryScope = deliveryScope
		},
		SET_ADDRESS: (state, addressInfo) => {
			state.addressInfo = addressInfo
		},
		SET_SETTLE: (state, settleList) => {
			state.settleList = settleList
		},
		SET_SHOP_CAR: (state, shop_car) => {
			state.shop_car = shop_car
		},
		SET_CITYOBJECT: (state, city) => {
			state.cityObject = city
		},
		HEIGHT_DATA: (state, heightData) => {
			state.heightData = heightData
		},
		ADD_ALBUM: (state, albumData) => {
			state.albumData = albumData
		},
		SET_CITY_LIST: (state, data) => {
			state.allCityList = data;
		},
		SET_CITY_COMPLETE: (state, data) => {
			state.allCityComplete = data;
		}
	},

	actions: {
		COMMIT_CITY_LIST: async({commit}, data) => {
			let res = await Common.getChinaList();
			console.log(res)
			let cityList = organizeArray(res.rows);
			console.log(cityList)
			commit('SET_CITY_LIST', cityList);
			commit('SET_CITY_COMPLETE', res.rows || []);
		}
	}
}

export default global